<template>
    <!-- 组件结构 -->
    <div class="student">
        <h2>学生姓名：{{name}}</h2>
        <h2>学生性别：{{sex}}</h2>
        <button @click="triggerEvent">点击发送学生姓名给App</button>
        <button @click="triggerEventBro">点击发送学生姓名给School</button>
    </div>
</template>
<script>
import { inject } from 'vue'
import { getCurrentInstance } from 'vue';
import emitter from '../eventBus';
    export default {
        name: 'Student',
        data(){
            return{

            }
        },
        setup(){
            const name = 'Aurora'
            const sex='男'
            const hello = inject('hello');
            const triggerEvent = ()=>{
                if(hello){
                    hello('Student')
                }
            }
            const triggerEventBro = ()=>{
                emitter.emit('hiBro','Student')
            }
           
            return{
                name,
                sex,
                triggerEvent,
                triggerEventBro,
            }
        },
        mounted(value){
        },
    }
</script>
<style scoped>
    .student{
        background-color: pink;
        padding:5px;
        margin-top: 30px;
    }
</style>
